﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="juriidiline_isikType_v3", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(JuriidilineIsikTypeV3))]
    public class JuriidilineIsikTypeV3Serializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IJuriidilineIsikTypeV3 clazz;
        
        public JuriidilineIsikTypeV3Serializer(IJuriidilineIsikTypeV3 clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("arinimi");
            if (clazz.Arinimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Arinimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Arinimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("registrikood");
            if (clazz.Registrikood!=null) {
                global::Xtee.Core.SerializationMetadata metaRegistrikood = this.GetMetaData(clazz.Registrikood);
                Writer.WriteTypeAttribute(metaRegistrikood.TypeQualifiedName.Namespace, metaRegistrikood.TypeQualifiedName.Name);
                metaRegistrikood.NewSerializer(clazz.Registrikood).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Registrikood");
            }
            Writer.WriteEndElement();
            if (clazz.Aadress!=null) {
                Writer.WriteStartElement("aadress");
                global::Xtee.Core.SerializationMetadata metaAadress = this.GetMetaData(clazz.Aadress);
                Writer.WriteTypeAttribute(metaAadress.TypeQualifiedName.Namespace, metaAadress.TypeQualifiedName.Name);
                metaAadress.NewSerializer(clazz.Aadress).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            if (clazz.Email!=null) {
                Writer.WriteStartElement("email");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Email))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="arinimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>juriidiline_isikType_v3>arinimi");
                }
                clazz.Arinimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("arinimi")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>juriidiline_isikType_v3>arinimi", Reader.LocalName);
            }
            if (Reader.LocalName=="registrikood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>juriidiline_isikType_v3>registrikood");
                }
                global::Xtee.Core.SerializationMetadata metaRegistrikood = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IRegistrikoodType>(Reader, "registrikoodType", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.Registrikood = metaRegistrikood.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IRegistrikoodType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("registrikood");
                    metaRegistrikood.NewSerializer(clazz.Registrikood).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>juriidiline_isikType_v3>registrikood", Reader.LocalName);
            }
            if (Reader.LocalName=="aadress") {
                if ((Reader.IsElementNil() == false)) {
                    global::Xtee.Core.SerializationMetadata metaAadress = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IAadressType>(Reader, "aadressType", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                    clazz.Aadress = metaAadress.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IAadressType>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("aadress");
                        metaAadress.NewSerializer(clazz.Aadress).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="email") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>juriidiline_isikType_v3>email");
                }
                clazz.Email = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("email")).Value;
            }
        }
    }
}
